package com.example.webdome.util;

import com.example.webdome.pojo.UrlNumber;
import com.example.webdome.service.UrlNumberService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class urlCount {
    @Resource
    private UrlNumberService urlNumberService;

    public void recordUrlCount(String url) {
        int currentCount = urlNumberService.getUrlNumber(url);

        UrlNumber urlNumber=new UrlNumber();
        urlNumber.setUrl(url);
        if (currentCount == 0) {
            // 今日没有记录，添加新记录
            urlNumber.setNumber(1);
            urlNumberService.save(urlNumber);
        } else {
            // 今日已有记录，更新次数
            urlNumberService.update().setSql("number = number + 1").update();

        }
    }
}
